package br.inf.solutions.apresentacoes.ssp.model;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import br.com.vexillum.model.CommonEntityActivated;
import br.com.vexillum.model.annotations.SearchField;
import br.com.vexillum.model.annotations.ValidatorClass;
import br.inf.solutions.apresentacoes.ssp.model.basics.SectorAddress;

@SuppressWarnings("serial")
@ValidatorClass(validatorClass="br.inf.solutions.apresentacoes.ssp.control.validator.NeighborhoodValidator")
@Entity
@Table(name="neighborhood")
public class Neighborhood extends CommonEntityActivated implements Comparable<Neighborhood> {

	@SearchField
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="id_sector", nullable=true, updatable=true)
	private SectorAddress sector;
	
	@SearchField
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="id_city", nullable=false, updatable=true)
	private City city;

	@SearchField
	@Column(name="name", nullable=false, unique=false, updatable=false, length=100)
	private String name;
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy="neighborhood",targetEntity=Address.class)	
	private List<Address> neighborhoods;

	public SectorAddress getSector() {
		return sector;
	}

	public void setSector(SectorAddress sector) {
		this.sector = sector;
	}

	public City getCity() {
		return city;
	}

	public void setCity(City city) {
		this.city = city;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return this.name;
	}

	@Override
	public int compareTo(Neighborhood o) {
		return this.name.compareTo(o.getName());
	}	
}